<?php
/**
 * Created by PhpStorm.
 * User: W
 * Date: 2019/1/7
 * Time: 16:31
 */

namespace app\sports_admin\controller;
use think\Request;
use app\sports_admin\model\Story as StoryModel;
use app\exception\StoryException;

class Story extends Base
{
    //优秀教师事迹页面
    public function index()
    {
        return view('index');
    }

    /**
     * 优秀教师事迹列表
     * @return array
     */
    public function storyList()
    {
        $params = Request::instance()->only(['page','rows','sort','sortOrder','searchName']);
        $page = intval($params['page']) ? intval($params['page']) : 1;
        $rows = intval($params['rows']) ? intval($params['rows']) : 15;
        $sort = trim($params['sort']) ? trim($params['sort']) : 'school_id';
        $sortOrder = trim($params['sortOrder']) ? trim($params['sortOrder']) : 'asc';
        $searchName = trim($params['searchName']);
        $result = StoryModel::storyList($page,$rows,$sort,$sortOrder,$searchName);
        return $result;
    }
    //优秀教师事迹详情
    public function storyMessage()
    {
        $data = StoryModel::storyMessage();
        return view('message',compact('data'));
    }
    //删除优秀教师事迹
    public function storyDel(Request $request)
    {
        if($request->isAjax()){
            $data = StoryModel::storyDel();
            if(!$data){
                throw new PlanException([
                    'msg'=>'删除失败',
                    'errorCode'=>'400']);
            }
            return json(['code'=>201,'msg'=>'删除成功']);
        }
    }
    //添加优秀教师事迹页面
    public function storyAddPage()
    {
        return view('add');
    }
    //添加游戏教师事迹
    public function storyAdd(Request $request)
    {
        if($request->isAjax()){
            $data = StoryModel::storyAdd();
            if(!$data){
                throw new StoryException([
                    'msg'=>'添加失败',
                    'errorCode'=>'400']);
            }
            return json(['code'=>201,'msg'=>'添加成功']);
        }
    }
    //优秀教师事迹 详细信息
    public function storyDetail()
    {
        $data = StoryModel::storyDetail();
        return view("message",compact("data"));
    }
    //优秀教师事迹更新
    public function storyUpdate(Request $request)
    {
        if($request->isAjax()){
            $data = StoryModel::storyUpdate();
            if(!$data){
                throw new StoryException([
                    'msg'=>'修改失败',
                    'errorCode'=>'400']);
            }
            return json(['code'=>201,'msg'=>'修改成功']);
        }
    }
}